package com.bwei.wangchao.topnews;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.bwei.wangchao.base.DataBase;

public class MainActivity extends AppCompatActivity {

    private TextView text;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        text = (TextView) findViewById(R.id.text);
        DataBase dataBase = new DataBase() {
            @Override
            public void setResultData(String json) {
                text.setText(json);
            }

            @Override
            protected void setResultFail(int errorCode) {
                if (errorCode == DataBase.ERROR_NET) {
                    Log.i("TAG", "请检查网络设置...");
                } else {
                    Log.i("TAG", "网络请求出现错误...");

                }
            }

            @Override
            protected void timeDelay() {

                Log.i("TAG", "本地存放时长已过时，从新请求网络");
            }
        };

        dataBase.getData("http://www.baidu.com", 1000 * 10 );

    }
}
